package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.FormBean;
import beans.MakersBean;
import beans.NameBean;

public class ConfirmControl extends HttpServlet{
	private static final long serialVersionUID = 1L;
	
	public ConfirmControl(){
		System.out.println("ConfirmControl()");
	}
	
	public void init(){
		System.out.println("ConfirmControl.init()");
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	  throws ServletException, IOException{
		System.out.println("ConfirmControl.doGet()");
		RequestDispatcher dispatcher;
		NameBean nb = new NameBean();
		nb.populate( request );
		if(nb.validate())
		{
			request.setAttribute("naam", nb);
			dispatcher = request.getRequestDispatcher("/bye");
		} else {
			dispatcher = request.getRequestDispatcher("/main");
		}
	    dispatcher.forward(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	  throws ServletException, IOException{
		System.out.println("ConfirmControl.doPost()");
		FormBean fb = (FormBean)request.getAttribute("form");
		MakersBean mb = new MakersBean();
		RequestDispatcher dispatcher;
		if(fb.validate())
		{
			request.setAttribute("naw", fb);
			request.setAttribute("mb", mb);
			dispatcher = request.getRequestDispatcher("/Confirm.jsp");
		} else {
			dispatcher = request.getRequestDispatcher("/main.jsp");
		}
	    dispatcher.forward(request, response);
	}
	public void destroy(){
		System.out.println("ConfirmControl.destroy()");
	}
}
